<?php

require('functions/pageLoad.php');

if(isset($_GET['delete'])){

	$sql = "DELETE FROM adverts WHERE id = '".$_GET['delete']."'";
	$query=mysql_query( $sql ) or die ("Error in query: $sql . " . mysql_error());

}

	$content = '<h2>Adverts</h2><p><a href="add_advert.php">Create new advert</a></p><table width="100%"><tr><th style="text-align: left;">Name</th><th>Type</th><th>Edit</th><th>Delete</th></tr>';

	$sql = "SELECT id, name, type FROM adverts ORDER BY id DESC";
	$query=mysql_query( $sql ) or die ("Error in query: $sql . " . mysql_error());
	while($rs=mysql_fetch_assoc($query)){
	
	$type = ($rs['type'] == '1') ? 'Content banner' : 'Column banner' ;
	
	$content.='<tr><td style="text-align: left;">'.$rs['name'].'</td><td>'.$type.'</td><td><a href="edit_advert.php?id='.$rs['id'].'"><img src="images/edit.gif" alt="Edit" /></a></td><td><a href="?delete='.$rs['id'].'"><img src="images/delete.gif" alt="Delete" /></a></td></tr>';
	
	}
	
	$content.='</table>';


require('includes/meta.php');
require('includes/header.php');
require('includes/leftColumn.php');
?><div id="middleColumn"><div id="content">
<?php echo $content; ?>
</div>
</div>
</div>

<?php
require('includes/footer.php');
?>